/*    Copyright 2010 Tobias Marschall
 *
 *    This file is part of MoSDi.
 *
 *    MoSDi is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    MoSDi is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MoSDi.  If not, see <http://www.gnu.org/licenses/>.
 */

package mosdi.tests;

import junit.framework.TestCase;
import mosdi.fa.Alphabet;
import mosdi.matching.BNDMatcher;
import mosdi.matching.BackwardOracleMatcher;
import mosdi.matching.HorspoolMatcher;
import mosdi.matching.Matcher;

public class MatcherTest extends TestCase {

	static final Alphabet dnaAlphabet = Alphabet.getDnaAlphabet();
	static final int[] text0 = dnaAlphabet.buildIndexArray("AGCTCGTTGATCTTCGCTCGTGAACTCTCAGGTATCAAGAACTCTCCGTGAAGCATGGCAAGCGATAGTTGGGTAACCCATCAGTGGGGGAATACTAGTGACCCCGACTGCGCCGAGGGTTAAAACCCGACTGCTGAGTATAGAGATTGCATGGCTTTCAGGCACCACACTACAAGGTGGCCAACGTGTACTCATCTGTGCATTAAAAATGAAGGGCATCCGCTGAGGCCACGGTTCGTTAATTGTATCATCTCAAGCAAGCAACGGGACACGCGCGTCATTCTTATTGTACTCAACGTCCTTAATCCATCGACCCATGGCTTGGAGATGCTCGACCCTAGTGTAATTCAAGGCCGGCGGTGTTGCCTAATCAAGTACCGAGTATAAAGGGCACCACCTGCTCGAGGCCACTTAAAATAGCCCGTCGGATGAGTAAGAAGCGAGGCGCGCACGCTATGCCCAACTAGAGGGTTGAGAGGATGTTAGTTTTCCTAAGCTCGTAATATTACCACCTGCTTTTTCGAGATTGTTATATCTGCGAAGGTCCTTCCGATAGGGCCTATATGATCCGCAAGTGTTCACGCCGGGACCCTTGCTTGCGCAAATACGCCTTCTTCCCTTACGCTACTCTCGGAGGTACGAGATGGCCCTGTCTCTATACTCGACGAGCCAAATTTTTGATATCAGGAAGATTTAGTATCGGAGGATGCGGTTCCGCTGTAGCGTCATGCTGACACAGTATTCTGCTTGATCGGTTTGCCACTCTGAGCACTGAATTAATATTTTCAGCCGCGACGGACGATCGTCAAAGCTTACACTAATTTCCCTAGTCTACTTCTGCCCGGCCGAACGATTGGCCTGCACTTCGGTCAGGTGGAGTGTCATGCTTCAATTTACTATTGCACCTCTATATTGATCCGTCCTCCAACCTAACCAAACAGGTCCTAGGTGCTTAATTGAGGTGCCATCATGAGCGATTTTTTCGCCTAAGTAGGTGACTTTCTGA");
	static final int[] text1 = dnaAlphabet.buildIndexArray("GACCAGTTCGTTTGAATCTCGGCCAATCCCGTAGAAGCAGGAATGGGGGTCACGGTCATTGAAGAAGGCACCCTGTGTGCCCAGCGCCGTATTAGGGGACCTATTGCTGCAAAGGAACTAACACGTAAATCCGCGAAGCGGAACCTAGTGTTCTCTCAGGCGTTGCAAAGATGGCCACGCCAAGAAATCGGAGTATCCTCGTCAATCAGCCTTGATACGAGAGGTACATCTCGTCCGCTGCTAGATTTCCGCATTAAATGGTGATGAATGCCTATACTCTTGCACAACGGGGAAAACTGCCTGTCAGACCTTTTAACTGGAATGAGACAGGGCTCGCTCGCTGGATCGCTGGATTATCCAACTGGTATCACAGGTTCTTATTCCTGTGCCTAGAAGTTACCGGACTGGCTATAGACTAGTATTCACCCGCATGATTATGATTAGGGTGGCCCGAAGTACCGACCTCACTGAGAACTGTCAATCTGCTTTGGCCTGGTCGGGATTGCGTCAAAGTGCTTTTACGGTTAATCGTGAATTTAGTAAGAGATCAAAGAGCGGGGTTTCGGTGTCACTCTTTGTATACATTTCCCGTGACAGTATTACGGCCTGTGATAACAACTGCGTATTTATAATCTGAAAACCCTACGACTGCTACGAAAGAACCGCAAATCGGGGCCACACACGAAGCGGGATGTCTGTCGACAAGATGTGCTCTGCAGACTCTTTCGTCCGAATTTCCTTTGGATTCCGATCTGGTGGTGGCGGCTACACTCTAGAGCCCTGTTCTCCCCTCGGCGACCAATATTACGAAGAACGAAACTGTGCTTTGGAGAAGTGACTTGCAAGACAAGTCACAGCACTTTATAGCCCGACGGATGCCAAGTCCGGTCATTGGCGGCTCGGCTTACCATCCGCGTACCGCTAACCTACGACTGCTGATACAGGAACCTCAATATGTTCTGGACAAGGCCCGATGACTTCCTACCCGCCCCCAGGGTCGTCAAAA");
	static final int[] pattern = dnaAlphabet.buildIndexArray("GCTCG");
	
	public static void assertMatcher(Matcher matcher) {
		assertEquals(5, matcher.findMatches(text0));
		assertEquals(matcher.getCharacterAccesses(), matcher.costScheme().computeCost(text0));
		assertEquals(3, matcher.findMatches(text1));
		assertEquals(matcher.getCharacterAccesses(), matcher.costScheme().computeCost(text1));
	}
	
	public void testHorspool() {
		assertMatcher(new HorspoolMatcher(dnaAlphabet.size(), pattern));
	}
	
	public void testBNDM() {
		Matcher matcher = new BNDMatcher(dnaAlphabet.size(), pattern); 
		assertMatcher(matcher);
		// True value was determined using Sven's python implementation
		assertEquals(475, matcher.costScheme().computeCost(text0));
	}

	public void testBOM() {
		assertMatcher(new BackwardOracleMatcher(dnaAlphabet.size(), pattern)); 
	}
	
}
